/*
 * timer0.c
 *
 *  Created on: 16/01/2015
 *      Author: santiago
 */

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <inc/hw_ints.h>
#include <inc/hw_memmap.h>
#include <inc/hw_types.h>
#include <inc/lm4f120h5qr.h>
#include <driverlib/rom.h>
#include <driverlib/timer.h>
#include "driverlib/gpio.h"

//*****************************************************************************
//
// The interrupt handler for the first timer interrupt.
//
//*****************************************************************************

uint32_t uiDeviceSampleTime = 0;		// demora antes de enviar otro bit, para que el device lea el bus.
unsigned long ulTest=0;
extern uint8_t owBusy;

void Timer0AIntHandler(void) {
	//
	// Clear the timer interrupt.
	//
	ulTest++;
	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, !GPIO_PIN_2);
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_PIN_0);
	ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
	if(uiDeviceSampleTime == 0)	{
		owBusy = 0;
	}
	else {
		ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, uiDeviceSampleTime);
		ROM_TimerEnable(TIMER0_BASE, TIMER_A);
		uiDeviceSampleTime = 0;
	}
}
